package com.nara.driveinspringboot.web.servlet;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 21:05 2019/8/21
 * @Modified By:
 **/
@WebServlet(urlPatterns = "/hello",asyncSupported = true)
public class MyServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AsyncContext asyncContext = req.startAsync();

        asyncContext.start(() ->{
            try {
                resp.getWriter().append("hello");
                asyncContext.complete();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        //resp.getWriter().append("hello");
    }
}
